package com.cytech.cloudclinic.adapter;

import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.bean.PrescriptionTag;

import java.util.List;

public class AddTemplateAdapter extends BaseQuickAdapter<PrescriptionTag, BaseViewHolder> {

    private int currentPos = 0;

    public AddTemplateAdapter(List<PrescriptionTag> data) {
        super(R.layout.item_add_template_list, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, PrescriptionTag prescriptionTag) {

        LinearLayout container = baseViewHolder.getView(R.id.ll_template_header);
        TextView tv =  baseViewHolder.getView(R.id.tv_template_header);
        if(baseViewHolder.getLayoutPosition() == currentPos){
            container.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.shape_template_item));
            tv.setTextColor(ContextCompat.getColor(getContext(),R.color.colorPrimary));
        }else{
            container.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.shape_round_empty_bg_line_gray_10));
            tv.setTextColor(ContextCompat.getColor(getContext(),R.color.color_666666));
        }
        baseViewHolder.setText(R.id.tv_template_header,prescriptionTag.value);
    }

    public void setCurrentPos(int currentPos) {
        this.currentPos = currentPos;
        notifyDataSetChanged();
    }

    public String getCurrentSelectId(){
        return getData().get(currentPos).id;
    }
}
